package com.clj.service.impl;

import com.clj.entity.AdminDO_clj;
import com.clj.service.AdminService_clj;
import com.clj.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Author: Harry Chen
 * Date: 2023/02/24 15:55
 * Description:
 */
public class AdminServiceCljImpl_clj implements AdminService_clj {
    public boolean validateAdmin(AdminDO_clj adminDoClj) {
        String userName = adminDoClj.get用户名();
        String pwdParam = adminDoClj.get密码();
        String sql = "select 密码 from 用户表_陈林杰 where 用户名 = ?";

        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet resultSet = null;

        try {
            conn = DBUtil.getConn();
            if (conn == null) {
                return false;
            }
            ps = conn.prepareStatement(sql);
            ps.setString(1, adminDoClj.get用户名());
            resultSet = ps.executeQuery();
            while (resultSet.next()) {
                String password = resultSet.getString(1);
                if (adminDoClj.get密码().equals(password)) {
                    return true;
                }
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            DBUtil.closeRs(resultSet);
            DBUtil.closeConn(conn);
            DBUtil.closePs(ps);
        }

        return false;
    }
}
